package com.cjl.demo.domain;

import com.cjl.demo.file.AppendToFile;
import com.cjl.demo.file.ReadFromFile;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

/**
 * <p>Copyright: All Rights Reserved</p>
 * <p>Description: 随机生成域名</p>
 *
 * @ uthor chenjinliang
 * @ date: 2019/10/30
 */
public class DomainService {
        public static void main(String[] args) {
        String fileName2 = "C:/domain_zhonghuayingcai2.txt";
        String fileName1 = "C:/domain_zhonghuayingcai1.txt";
        Set<String> fileSet = ReadFromFile.readFileByLines(fileName1);
        int num = 100000, t = 0;
        Set<String> domainSet = new HashSet<>();
        while (domainSet.size() < num){
            Random random = new Random();
            char[] valArray = new char[4];
            for (int i = 0; i < 4; i++) {
                // 小写字母
                valArray[i] = (char) (97 + random.nextInt(26));
            }
            if(valArray[0] != valArray[1] && valArray[1]!= valArray[2] && valArray[2] !=valArray[3] && valArray[3] != valArray[0] && valArray[0] != 'x' && valArray[3] != 't'
                    && !(valArray[0]==valArray[1]-1 && valArray[0] == valArray[2]-2 )
                    && !(valArray[1] == valArray[2] -1 && valArray[1] == valArray[3] -2)){
                t++;
                String domain = "wx"+ valArray[0]+valArray[1]+valArray[2]+valArray[3]+"tongzhen.chinahr.com";
                if(!fileSet.contains(domain)){
                    System.out.println(domain);
                    domainSet.add(domain);
                }
            }
        }
            System.out.println("domainSet.size = [" + domainSet.size() + "]");
        for(String domain : domainSet){
            AppendToFile.appendMethodB(fileName2, domain+ "\n");
        }
        //按顺序生成域名
//        for(char i = 'a'; i <= 'z' && t< num; i++){
//            for(char j ='b'; j <= 'z'&& t< num; j ++){
//                for(char m = 'c'; m <= 'z'&& t< num; m ++){
//                    for(char n = 'd'; n <= 'z'&& t< num; n ++){
//                        if(i != j && j!= m && m !=n && n != i && !(i==j-1 && i== m-2 )
//                                && !(j== m-1 && j == n-2)){
//                            t++;
//                            String domain = "wx"+ i+j+m+n+"tongzhen.58.com";
//                            System.out.println(domain);
//                            AppendToFile.appendMethodB(fileName, domain+ "\n");
//                        }
//                    }
//                }
//            }
//        }
    }

}
